home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 151-175 / scopedisk164 / printicon / appicon.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  3KB  |  118 lines

  1. #define bufsize 1024
  2.  
  3. #include <intuition/intuition.h>
  4. #include <exec/memory.h>
  5. #include <workbench/startup.h>
  6. #include <workbench/workbench.h>
  7.  
  8. #include <stdio.h>
  9.  
  10. #include <clib/exec_protos.h>
  11. #include <clib/intuition_protos.h>
  12. #include <clib/icon_protos.h>
  13. #include <clib/wb_protos.h>
  14. #include <clib/dos_protos.h>
  15. #include <fcntl.h>
  16.  
  17.  
  18. struct IntuitionBase *IntuitionBase;
  19. struct WorkbenchBase *WorkbenchBase;
  20. struct IconBase *IconBase;
  21. struct MsgPort *msgport;
  22. struct AppIcon *ai;
  23. struct DiskObject *dobj;
  24. struct AppMessage *amsg;
  25. int prth; /* printer's file handle */
  26. int imagememsize = 0;
  27.  
  28. void CleanExit (int returnval);
  29. void PrintIcon (void);
  30.  
  31.  
  32. void CleanExit (returnval)
  33. int returnval;
  34. {
  35.     if (ai)
  36.         RemoveAppIcon(ai);
  37.     if (dobj)
  38.         FreeDiskObject(dobj);
  39.     if (msgport) {
  40.         while(amsg = (struct AppMessage *)GetMsg(msgport))
  41.         ReplyMsg((struct Message *)amsg);
  42.         DeleteMsgPort(msgport);
  43.     }
  44.     if  (IconBase) 
  45.         CloseLibrary(IconBase);
  46.     if (WorkbenchBase)
  47.         CloseLibrary(WorkbenchBase);
  48.     if (IntuitionBase)
  49.         CloseLibrary(IntuitionBase);
  50.     if (prth)
  51.         close(prth);
  52.     exit (returnval);
  53. }
  54.     
  55.  
  56. void main(void)
  57. {
  58.     if (!(IntuitionBase = OpenLibrary("intuition.library", 36)))
  59.         CleanExit(10);
  60.     if (!(WorkbenchBase = OpenLibrary("workbench.library", 36)))
  61.         CleanExit(10);
  62.     if (!(IconBase = OpenLibrary("icon.library", 36)))
  63.         CleanExit(10);
  64.     if (!(msgport = CreateMsgPort()))
  65.         CleanExit(10);
  66.     if (!(dobj = GetDiskObject("printicon")))
  67.         CleanExit(10);
  68.     PrintIcon();
  69. }
  70.  
  71. void PrintIcon()
  72. {
  73.     struct WBArg   *argptr;
  74.     int fh, length_read;
  75.     char buffer[bufsize];
  76.     int flag; /* your generic run-of-the-mill flag */
  77.  
  78.     BOOL            done = FALSE;
  79.     int             i;
  80.  
  81.  
  82.     if (!(ai = AddAppIcon(1, 0, "PrintIt", msgport, NULL, dobj, NULL)))
  83.         CleanExit(10);
  84.     do {
  85.         Wait(1 << msgport->mp_SigBit);
  86.         while (amsg = (struct AppMessage *) GetMsg(msgport)) {
  87.             if (amsg->am_NumArgs == 0) {
  88.                 done = TRUE;
  89.                 break;
  90.             }
  91.             argptr = amsg->am_ArgList;
  92.             for (i = 0; i < amsg->am_NumArgs; i++) {
  93.                 if (*(argptr->wa_Name)) {
  94.                     CurrentDir(argptr->wa_Lock);
  95.                     if (!(prth = open("PRT:",O_WRONLY,0))) 
  96.                         CleanExit(10); 
  97.                     fh = open(argptr->wa_Name,O_RDONLY,0);
  98.                     if (fh) {
  99.                         length_read = bufsize;
  100.                         flag = 1;
  101.                         while (length_read == bufsize && flag != -1) {
  102.                             length_read = read(fh, &buffer, bufsize);
  103.                             if (length_read != -1)
  104.                                 flag = write(prth, &buffer, length_read);
  105.                         }
  106.                         if (flag != -1 && length_read != -1)
  107.                             write (prth, "\f", 1); /* send form feed */
  108.                         close(fh);
  109.                         close(prth);
  110.                     }
  111.                 }
  112.                 argptr++;
  113.             }
  114.             ReplyMsg((struct Message *) amsg);
  115.         }
  116.     } while (!done);
  117.     RemoveAppIcon(ai);
  118. }